home *** CD-ROM | disk | FTP | other *** search
- Path: linux.nildram.co.uk!usenet
- From: colin@greench.co.uk (Colin Wray)
- Newsgroups: comp.lang.c++
- Subject: Re: when to inherit, when to compose...
- Date: Fri, 29 Mar 1996 21:57:33 GMT
- Organization: Greenchurch Software Ltd
- Message-ID: <4jhmmq$smd@linux.nildram.co.uk>
- References: <4j943p$7es@ulowell.uml.edu>
- NNTP-Posting-Host: pppn.nildram.co.uk
- X-Newsreader: Forte Free Agent 1.0.82
-
- jlee@jupiter.cs.uml.edu (John Peter Lee) wrote:
-
- >Hi:
-
- > I'm wondering about an OO design. Under what circumstances is it more
- > advantageous to use an inheritance hierarchy for a design, as opposed
- > to using object containment, and vice versa?
-
- > With object containment: class "A" has a member class "B" declared
- > within it. A acts as a kindof handle class (I think) that forwards
- > requests to B, and handles B's output.
-
- > With inheritance: class "A" is a base class, and class "B" is a derived
- > class. Then A has virtual functions that are implemented in B.
-
- > -> Are there any general rules of thumb to apply here? Any literature?
-
- Composition: "A" has a "B".
- Inheritance: "A" is a kind of "B"
- "Car" is a kind of "Vehicle" that has a "Engine".
-
- >
- > The design I am currently developing involves classes that are graphical
- > in nature - they have a lot of Motif and graphics-related info. I want to
- > shield all of this graphics stuff from certain objects that interact with
- > these classes in a non-graphical way (I'm placing graphics descriptors
- > into a type of history structure, and doing a lot of manipulations of
- > these descriptors - actual graphics isn't required for any of this stuff).
- > I'm wondering whether or not to shield things via containment by having
- > a graphical class ptr as a member of the base class, or via inheritance by
- > having a subclass inherit the graphical stuff from a graphical base class.
-
- The objects should already encapsulate their data structures, making
- them accessable only via their API. If the graphical functions are
- protected, they would only be accessable by 'friend' class functions.
-
- >thanks in advance - please reply directly to me.
-
- >jp
-
- >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- >JP Lee Institute for Visualization and Perception Research
- >jlee@cs.uml.edu University of Massachusetts at Lowell
- >(508) 934-3384 1 University Ave. Lowell, MA 01854
- >(508) 452-4298 fax
-
- > Don't accept cheap imitations !!!!
-
- > Support H.R. 1500 - America's Redrock Wilderness Act !
-
- >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
- ----------------------------------------------------------------------------
- Colin Wray, Greenchurch Software Ltd, UK
- Email: colin@greench.co.uk
- ----------------------------------------------------------------------------
-
-